package com.cxhome.cxinfox.report;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Record;
import com.traffic.managent.annotation.ControllerBind;
import com.traffic.managent.base.CxBaseController;
import com.traffic.managent.model.system.Department;
import com.traffic.managent.util.StringUtils;

/**
 * 统计报表管理
 * 
 * @author Guoxing
 *
 */
@ControllerBind(controllerKey = "/system/dayreport")
public class DayReportController extends CxBaseController {

	private static final String path = "/pages/system/dayreport/dayreport_";

	/**
	 * 默认方法
	 */
	public void index() {
		list();
	}

	/**
	 * 统计list
	 */
	public void list() {

		Map<String, Object> params = new HashMap<String, Object>();

		// 当前登录用户所属组织机构
		String departmentId = getSessionUser().getStr("departmentId");
		// ***从组织机构数据表中查询出该组织结构所有的实际子组织机构id(含本身)***
		String tempIdsStr = Department.dao.queryChildIds(departmentId);
		String tempIdsStr1 = tempIdsStr.replaceAll(",", "','");
		String idsStr = "";
		if (tempIdsStr1.contains(",")) {
			idsStr = "('" + tempIdsStr1 + "')";
		} else {// 组织机构只有一个时查询语句会报错
			idsStr = "('" + tempIdsStr1 + "','" + tempIdsStr1 + "')";
		}

		String customerId = getSessionUser().getStr("customerId");
		if (customerId !=null && !"".equals(customerId)) { // 表示管理员登陆
			// 根据组织结构参数查询
			params.put("departmentId", idsStr);
			params.put("action", "adminReport");

		} else { // 表示客户登陆

			params.put("customerId", customerId);
		}

		params.put("startDate", getPara("attr.startDate"));
		params.put("endDate", getPara("attr.endDate"));
		List<Record> list = DayReportService.service.listReport(params);
		setAttr("startDate", getPara("attr.startDate"));
		setAttr("endDate", getPara("attr.endDate"));
		setAttr("listReport", list);
		setAttr("listSize", list != null ? list.size() : 0);
		setAttr("action", "cstmReport");

		render(path + "list.html");
	}
	

}
